// Copyright 2025 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <stddef.h>

#include <cstdint>
#include <vector>

#include "algebra/fp.h"
#include "circuits/cbor_parser_v2/cbor.h"
#include "circuits/cbor_parser_v2/cbor_testing.h"
#include "circuits/cbor_parser_v2/cbor_witness.h"
#include "circuits/logic/evaluation_backend.h"
#include "circuits/logic/logic.h"
#include "gf2k/gf2_128.h"
#include "gtest/gtest.h"

namespace proofs {
namespace {
/*
    Decoding of the example:

A6                                      # map(6)
   67                                   # text(7)
      76657273696F6E                    # "version"
   63                                   # text(3)
      312E30                            # "1.0"
   6F                                   # text(15)
      646967657374416C676F726974686D    # "digestAlgorithm"
   67                                   # text(7)
      5348412D323536                    # "SHA-256"
   6C                                   # text(12)
      76616C756544696765737473          # "valueDigests"
   A2                                   # map(2)
      71                                # text(17)
         6F72672E69736F2E31383031332E352E31 # "org.iso.18013.5.1"
      B8 2B                             # map(43)
         00                             # unsigned(0)
         58 20                          # bytes(32)
            9F764FEF7CD0D9226AF6E38F71FA281EA44DC97C3019A39CDD10E832872AA59A
         01                             # unsigned(1)
         58 20                          # bytes(32)
            41335B076B589CEFB7FC62143ADF3323069E885FF2E3E84EE905056AC9F7AB79
         02                             # unsigned(2)
         58 20                          # bytes(32)
            0FA28177FD958101AB6722421FBACA0C38594807D735A46AA4214EACF0E5AAA5
         03                             # unsigned(3)
         58 20                          # bytes(32)
            E3AD1C7DEE0DA1DDEDE6080C3B7FAE97035FFDB418DAE775F1E10817E1395FA9
         04                             # unsigned(4)
         58 20                          # bytes(32)
            586D5F928DA86071AF5AEA4B16DD795F99E45D35AECD30195B92F1EA6481F5C1
         05                             # unsigned(5)
         58 20                          # bytes(32)
            FC5E2D29D7DB42D63AA2EE8E6924ACA947732E6C62704029E0FECB87CF170F37
         06                             # unsigned(6)
         58 20                          # bytes(32)
            EA29563A32A346DDFC940D42DCDE4A0CEC3DB130E9073C624AE8D23B60F28748
         07                             # unsigned(7)
         58 20                          # bytes(32)
            D36E6B84B4B2A629D9543C28BC6DC29A67F643696F1DAB192989B6AA9351CA08
         08                             # unsigned(8)
         58 20                          # bytes(32)
            393FF4D76A884156FCFAE5AE4BB73510D2A51E09AE3AD10817B0931CA982C818
         09                             # unsigned(9)
         58 20                          # bytes(32)
            40CAB6EADAF859C5C92F39B8D091949D5215044EA2C99DB21995FCA45B102EE0
         0A                             # unsigned(10)
         58 20                          # bytes(32)
            F2343744267FCD80B8FAB893283E3015D6E79A86F5571D742C8830958E73CDE9
         0B                             # unsigned(11)
         58 20                          # bytes(32)
            2EB472B2FE3DA6D518701622B7022C34043647EE5554FBE08874391BBBDA23E7
         0C                             # unsigned(12)
         58 20                          # bytes(32)
            A5C87C6499B67F38ACA2B6585D115DC5259DCBDAC2DCEDA92DC476CF817FC11B
         0D                             # unsigned(13)
         58 20                          # bytes(32)
            6C0A6DDDE77BB27A0C876AABF14CF20D921DE8648D8CE54A33E1A46A09E66E4E
         0E                             # unsigned(14)
         58 20                          # bytes(32)
            D6FF79077E79A9DC94F4E0DA16AD58E8A0CD7CEDB01A19CA7AC6D7AB3460E23A
         0F                             # unsigned(15)
         58 20                          # bytes(32)
            A899B4B1F57CFB8AC8084B65E9B8B087975ECDFEE2918DAB5F9D4B819518C0BE
         10                             # unsigned(16)
         58 20                          # bytes(32)
            8850EEB5DB6E291F9FD995E8AC539529FF2CE125B3A79B913E6E5EBEFA880E76
         11                             # unsigned(17)
         58 20                          # bytes(32)
            DDFD87771C16848C4999E98711D6E82478F7EBC479A9A83F1BC31D3E51BC821E
         12                             # unsigned(18)
         58 20                          # bytes(32)
            C8BA11F4E182108DEB38890E4158A83AA9863A5E9322071C13B4278E0D389808
         13                             # unsigned(19)
         58 20                          # bytes(32)
            87AE60874B2603B8A84AA9E76FEB1F23468BF9420A2A3C03536E35CAE5958BC1
         14                             # unsigned(20)
         58 20                          # bytes(32)
            F34F4E5485DE8938C5A9AB37EA3BBD6E67F5EF1F8319D64562EE063CBADE002C
         15                             # unsigned(21)
         58 20                          # bytes(32)
            ECE81153961D98DEE85D819E0AC1EEF2141806FFEF7684932B94C354E17350CC
         16                             # unsigned(22)
         58 20                          # bytes(32)
            9AB1EB8CA05422E2D70E73EF8289184CF8EDCF4E40DA39347BA40425550CE65F
         17                             # unsigned(23)
         58 20                          # bytes(32)
            C7B3886BBC9051076F5AD2D530142E7FBFAF3128CC21392FAF1D3EE0E5F8933B
         18 18                          # unsigned(24)
         58 20                          # bytes(32)
            083697C66436B25FCF8AA0CC9556126D94012013A58C70F8E885C02D2F5238EC
         18 19                          # unsigned(25)
         58 20                          # bytes(32)
            037BD4447E09A5D7AADCB3593D05E4C17AA230AF60E7C8D30C29AFC97AD9815D
         18 1A                          # unsigned(26)
         58 20                          # bytes(32)
            1970C3AC3C55D82702CE9F8ED7760832386E5FDDAF4E352D4CF953A15E40ACEC
         18 1B                          # unsigned(27)
         58 20                          # bytes(32)
            C4BBFAAF6BD490962861F63398DA8FAD19C26E1DACD07D5291E9A22CDAF5319E
         18 1C                          # unsigned(28)
         58 20                          # bytes(32)
            24AA53A9B4120C192DF790EE170E38535655FA5637B661C0EF26AA3B357DB604
         18 1D                          # unsigned(29)
         58 20                          # bytes(32)
            4E1396CCDC527D296D650184256860ECE3F379AD4900899F171544AFF5B950A3
         18 1E                          # unsigned(30)
         58 20                          # bytes(32)
            7648D830A5F2D49354BA3E65F4497131D63748C747748E7909BAEEEC82279A76
         18 1F                          # unsigned(31)
         58 20                          # bytes(32)
            2ECDDA6BE9985C3FCBB2FB0852CC1F994018A5AB1310661F7AD1FF44BB622CF9
         18 20                          # unsigned(32)
         58 20                          # bytes(32)
            C67442548CCB44996823748506D7FBE38802F2AB95B2937FB9B4B5FB95CD362E
         18 21                          # unsigned(33)
         58 20                          # bytes(32)
            770487D5590519E5E75785199F0D1785DB096E959434A0FFD19D866455A387A8
         18 22                          # unsigned(34)
         58 20                          # bytes(32)
            12F6BC766780E9059378495CDE5E47F78BE351D50DD53E518EB3A68FDFAFDCB3
         18 23                          # unsigned(35)
         58 20                          # bytes(32)
            D5B848D4EDB7680C1674620B45474002E29A59E9B747C59875713F39D0DE4326
         18 24                          # unsigned(36)
         58 20                          # bytes(32)
            F11E3EEC4BE51AE12EABFB52B4CACA059ADA766FC55990F2C9C8AAE36E3DC415
         18 25                          # unsigned(37)
         58 20                          # bytes(32)
            7ED8D09F036A1D6305189EC708659C4BFD11E1F81348F559464BDEB8B709BAC0
         18 26                          # unsigned(38)
         58 20                          # bytes(32)
            48FEAFFA4FE8A71B417E914AB7DEE179B497199FE4879D894DCB9D8CC66BCD73
         18 27                          # unsigned(39)
         58 20                          # bytes(32)
            E5AEF986F9D62470BC154E103EEC191053ADAB466A101C4A4EA3EE1A1E025C2C
         18 28                          # unsigned(40)
         58 20                          # bytes(32)
            BAAE3DD3E7EAAA5FB84F24E575223902B138F854575213CBB70D741AB466F015
         18 29                          # unsigned(41)
         58 20                          # bytes(32)
            4CB132396ABC658FEDDC1A7C2A6A4D1CD458D23805488E287A2BDC020C9B4EFE
         18 2A                          # unsigned(42)
         58 20                          # bytes(32)
            EC64D65D4830B6013F70B0F21728788C2FD372126CB51AB1E5F7D26B83036022
      73                                # text(19)
         6F72672E61616D76612E31383031332E352E31 # "org.aamva.18013.5.1"
      A7                                # map(7)
         00                             # unsigned(0)
         58 20                          # bytes(32)
            BD1205F826496CEDD84271854628984D76C62AB6B7D4F68E04658D4E63DAA410
         01                             # unsigned(1)
         58 20                          # bytes(32)
            28A2A6F3FB47EE49758A06BE56B75DA5980A2EF7D4D6C6B00402C1023C97BEF6
         02                             # unsigned(2)
         58 20                          # bytes(32)
            DAF10E80D87EDDA4051BF121895CAD3FC595DB8D5AEB3526DE704B6F0E77ACFA
         03                             # unsigned(3)
         58 20                          # bytes(32)
            A6F80A0CBF80F42CC33E08F98E0D85CFC5A4B97D13C5D4BAD8992BFE5ABD9A92
         04                             # unsigned(4)
         58 20                          # bytes(32)
            062632510EEFBB338C12228D8CA299D4C07C34F12CCCF86C519472528D8FBC9A
         05                             # unsigned(5)
         58 20                          # bytes(32)
            CE4F3515E7C256095AC6B6AA4A4AF0AC8B964079BD627BC897F544087F2D2C7B
         06                             # unsigned(6)
         58 20                          # bytes(32)
            921AEC9FA8C51C6F90DE860F6E5F4D81C756F62A8FE6E19D9122E942DDB9BFA3
   6D                                   # text(13)
      6465766963654B6579496E666F        # "deviceKeyInfo"
   A1                                   # map(1)
      69                                # text(9)
         6465766963654B6579             # "deviceKey"
      A4                                # map(4)
         01                             # unsigned(1)
         02                             # unsigned(2)
         20                             # negative(0)
         01                             # unsigned(1)
         21                             # negative(1)
         58 20                          # bytes(32)
            61DC8B2C6E98E1A282B16F95F373C1B0B99EE47FA57191763F08B2FC1EBE9AF5
         22                             # negative(2)
         58 20                          # bytes(32)
            10CF01637F63CB7C53F8925FD2A37DEDEC6D04EAABE4DCCA94437962813AAF1C
   6C                                   # text(12)
      76616C6964697479496E666F          # "validityInfo"
   A3                                   # map(3)
      66                                # text(6)
         7369676E6564                   # "signed"
      C0                                # tag(0)
         74                             # text(20)
            323032342D30322D31345430383A30303A30305A # "2024-02-14T08:00:00Z"
      69                                # text(9)
         76616C696446726F6D             # "validFrom"
      C0                                # tag(0)
         74                             # text(20)
            323032342D30322D31345430383A30303A30305A # "2024-02-14T08:00:00Z"
      6A                                # text(10)
         76616C6964556E74696C           # "validUntil"
      C0                                # tag(0)
         74                             # text(20)
            323032352D30322D31345430383A30303A30305A # "2025-02-14T08:00:00Z"
   67                                   # text(7)
      646F6354797065                    # "docType"
   75                                   # text(21)
      6F72672E69736F2E31383031332E352E312E6D444C # "org.iso.18013.5.1.mDL"
*/
static constexpr size_t mso_nbytes = 2099;
static const uint8_t mso_example[mso_nbytes] = {
    0xA6, 0x67, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x63, 0x31, 0x2E,
    0x30, 0x6F, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6C, 0x67, 0x6F,
    0x72, 0x69, 0x74, 0x68, 0x6D, 0x67, 0x53, 0x48, 0x41, 0x2D, 0x32, 0x35,
    0x36, 0x6C, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x44, 0x69, 0x67, 0x65, 0x73,
    0x74, 0x73, 0xA2, 0x71, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E,
    0x31, 0x38, 0x30, 0x31, 0x33, 0x2E, 0x35, 0x2E, 0x31, 0xB8, 0x2B, 0x00,
    0x58, 0x20, 0x9F, 0x76, 0x4F, 0xEF, 0x7C, 0xD0, 0xD9, 0x22, 0x6A, 0xF6,
    0xE3, 0x8F, 0x71, 0xFA, 0x28, 0x1E, 0xA4, 0x4D, 0xC9, 0x7C, 0x30, 0x19,
    0xA3, 0x9C, 0xDD, 0x10, 0xE8, 0x32, 0x87, 0x2A, 0xA5, 0x9A, 0x01, 0x58,
    0x20, 0x41, 0x33, 0x5B, 0x07, 0x6B, 0x58, 0x9C, 0xEF, 0xB7, 0xFC, 0x62,
    0x14, 0x3A, 0xDF, 0x33, 0x23, 0x06, 0x9E, 0x88, 0x5F, 0xF2, 0xE3, 0xE8,
    0x4E, 0xE9, 0x05, 0x05, 0x6A, 0xC9, 0xF7, 0xAB, 0x79, 0x02, 0x58, 0x20,
    0x0F, 0xA2, 0x81, 0x77, 0xFD, 0x95, 0x81, 0x01, 0xAB, 0x67, 0x22, 0x42,
    0x1F, 0xBA, 0xCA, 0x0C, 0x38, 0x59, 0x48, 0x07, 0xD7, 0x35, 0xA4, 0x6A,
    0xA4, 0x21, 0x4E, 0xAC, 0xF0, 0xE5, 0xAA, 0xA5, 0x03, 0x58, 0x20, 0xE3,
    0xAD, 0x1C, 0x7D, 0xEE, 0x0D, 0xA1, 0xDD, 0xED, 0xE6, 0x08, 0x0C, 0x3B,
    0x7F, 0xAE, 0x97, 0x03, 0x5F, 0xFD, 0xB4, 0x18, 0xDA, 0xE7, 0x75, 0xF1,
    0xE1, 0x08, 0x17, 0xE1, 0x39, 0x5F, 0xA9, 0x04, 0x58, 0x20, 0x58, 0x6D,
    0x5F, 0x92, 0x8D, 0xA8, 0x60, 0x71, 0xAF, 0x5A, 0xEA, 0x4B, 0x16, 0xDD,
    0x79, 0x5F, 0x99, 0xE4, 0x5D, 0x35, 0xAE, 0xCD, 0x30, 0x19, 0x5B, 0x92,
    0xF1, 0xEA, 0x64, 0x81, 0xF5, 0xC1, 0x05, 0x58, 0x20, 0xFC, 0x5E, 0x2D,
    0x29, 0xD7, 0xDB, 0x42, 0xD6, 0x3A, 0xA2, 0xEE, 0x8E, 0x69, 0x24, 0xAC,
    0xA9, 0x47, 0x73, 0x2E, 0x6C, 0x62, 0x70, 0x40, 0x29, 0xE0, 0xFE, 0xCB,
    0x87, 0xCF, 0x17, 0x0F, 0x37, 0x06, 0x58, 0x20, 0xEA, 0x29, 0x56, 0x3A,
    0x32, 0xA3, 0x46, 0xDD, 0xFC, 0x94, 0x0D, 0x42, 0xDC, 0xDE, 0x4A, 0x0C,
    0xEC, 0x3D, 0xB1, 0x30, 0xE9, 0x07, 0x3C, 0x62, 0x4A, 0xE8, 0xD2, 0x3B,
    0x60, 0xF2, 0x87, 0x48, 0x07, 0x58, 0x20, 0xD3, 0x6E, 0x6B, 0x84, 0xB4,
    0xB2, 0xA6, 0x29, 0xD9, 0x54, 0x3C, 0x28, 0xBC, 0x6D, 0xC2, 0x9A, 0x67,
    0xF6, 0x43, 0x69, 0x6F, 0x1D, 0xAB, 0x19, 0x29, 0x89, 0xB6, 0xAA, 0x93,
    0x51, 0xCA, 0x08, 0x08, 0x58, 0x20, 0x39, 0x3F, 0xF4, 0xD7, 0x6A, 0x88,
    0x41, 0x56, 0xFC, 0xFA, 0xE5, 0xAE, 0x4B, 0xB7, 0x35, 0x10, 0xD2, 0xA5,
    0x1E, 0x09, 0xAE, 0x3A, 0xD1, 0x08, 0x17, 0xB0, 0x93, 0x1C, 0xA9, 0x82,
    0xC8, 0x18, 0x09, 0x58, 0x20, 0x40, 0xCA, 0xB6, 0xEA, 0xDA, 0xF8, 0x59,
    0xC5, 0xC9, 0x2F, 0x39, 0xB8, 0xD0, 0x91, 0x94, 0x9D, 0x52, 0x15, 0x04,
    0x4E, 0xA2, 0xC9, 0x9D, 0xB2, 0x19, 0x95, 0xFC, 0xA4, 0x5B, 0x10, 0x2E,
    0xE0, 0x0A, 0x58, 0x20, 0xF2, 0x34, 0x37, 0x44, 0x26, 0x7F, 0xCD, 0x80,
    0xB8, 0xFA, 0xB8, 0x93, 0x28, 0x3E, 0x30, 0x15, 0xD6, 0xE7, 0x9A, 0x86,
    0xF5, 0x57, 0x1D, 0x74, 0x2C, 0x88, 0x30, 0x95, 0x8E, 0x73, 0xCD, 0xE9,
    0x0B, 0x58, 0x20, 0x2E, 0xB4, 0x72, 0xB2, 0xFE, 0x3D, 0xA6, 0xD5, 0x18,
    0x70, 0x16, 0x22, 0xB7, 0x02, 0x2C, 0x34, 0x04, 0x36, 0x47, 0xEE, 0x55,
    0x54, 0xFB, 0xE0, 0x88, 0x74, 0x39, 0x1B, 0xBB, 0xDA, 0x23, 0xE7, 0x0C,
    0x58, 0x20, 0xA5, 0xC8, 0x7C, 0x64, 0x99, 0xB6, 0x7F, 0x38, 0xAC, 0xA2,
    0xB6, 0x58, 0x5D, 0x11, 0x5D, 0xC5, 0x25, 0x9D, 0xCB, 0xDA, 0xC2, 0xDC,
    0xED, 0xA9, 0x2D, 0xC4, 0x76, 0xCF, 0x81, 0x7F, 0xC1, 0x1B, 0x0D, 0x58,
    0x20, 0x6C, 0x0A, 0x6D, 0xDD, 0xE7, 0x7B, 0xB2, 0x7A, 0x0C, 0x87, 0x6A,
    0xAB, 0xF1, 0x4C, 0xF2, 0x0D, 0x92, 0x1D, 0xE8, 0x64, 0x8D, 0x8C, 0xE5,
    0x4A, 0x33, 0xE1, 0xA4, 0x6A, 0x09, 0xE6, 0x6E, 0x4E, 0x0E, 0x58, 0x20,
    0xD6, 0xFF, 0x79, 0x07, 0x7E, 0x79, 0xA9, 0xDC, 0x94, 0xF4, 0xE0, 0xDA,
    0x16, 0xAD, 0x58, 0xE8, 0xA0, 0xCD, 0x7C, 0xED, 0xB0, 0x1A, 0x19, 0xCA,
    0x7A, 0xC6, 0xD7, 0xAB, 0x34, 0x60, 0xE2, 0x3A, 0x0F, 0x58, 0x20, 0xA8,
    0x99, 0xB4, 0xB1, 0xF5, 0x7C, 0xFB, 0x8A, 0xC8, 0x08, 0x4B, 0x65, 0xE9,
    0xB8, 0xB0, 0x87, 0x97, 0x5E, 0xCD, 0xFE, 0xE2, 0x91, 0x8D, 0xAB, 0x5F,
    0x9D, 0x4B, 0x81, 0x95, 0x18, 0xC0, 0xBE, 0x10, 0x58, 0x20, 0x88, 0x50,
    0xEE, 0xB5, 0xDB, 0x6E, 0x29, 0x1F, 0x9F, 0xD9, 0x95, 0xE8, 0xAC, 0x53,
    0x95, 0x29, 0xFF, 0x2C, 0xE1, 0x25, 0xB3, 0xA7, 0x9B, 0x91, 0x3E, 0x6E,
    0x5E, 0xBE, 0xFA, 0x88, 0x0E, 0x76, 0x11, 0x58, 0x20, 0xDD, 0xFD, 0x87,
    0x77, 0x1C, 0x16, 0x84, 0x8C, 0x49, 0x99, 0xE9, 0x87, 0x11, 0xD6, 0xE8,
    0x24, 0x78, 0xF7, 0xEB, 0xC4, 0x79, 0xA9, 0xA8, 0x3F, 0x1B, 0xC3, 0x1D,
    0x3E, 0x51, 0xBC, 0x82, 0x1E, 0x12, 0x58, 0x20, 0xC8, 0xBA, 0x11, 0xF4,
    0xE1, 0x82, 0x10, 0x8D, 0xEB, 0x38, 0x89, 0x0E, 0x41, 0x58, 0xA8, 0x3A,
    0xA9, 0x86, 0x3A, 0x5E, 0x93, 0x22, 0x07, 0x1C, 0x13, 0xB4, 0x27, 0x8E,
    0x0D, 0x38, 0x98, 0x08, 0x13, 0x58, 0x20, 0x87, 0xAE, 0x60, 0x87, 0x4B,
    0x26, 0x03, 0xB8, 0xA8, 0x4A, 0xA9, 0xE7, 0x6F, 0xEB, 0x1F, 0x23, 0x46,
    0x8B, 0xF9, 0x42, 0x0A, 0x2A, 0x3C, 0x03, 0x53, 0x6E, 0x35, 0xCA, 0xE5,
    0x95, 0x8B, 0xC1, 0x14, 0x58, 0x20, 0xF3, 0x4F, 0x4E, 0x54, 0x85, 0xDE,
    0x89, 0x38, 0xC5, 0xA9, 0xAB, 0x37, 0xEA, 0x3B, 0xBD, 0x6E, 0x67, 0xF5,
    0xEF, 0x1F, 0x83, 0x19, 0xD6, 0x45, 0x62, 0xEE, 0x06, 0x3C, 0xBA, 0xDE,
    0x00, 0x2C, 0x15, 0x58, 0x20, 0xEC, 0xE8, 0x11, 0x53, 0x96, 0x1D, 0x98,
    0xDE, 0xE8, 0x5D, 0x81, 0x9E, 0x0A, 0xC1, 0xEE, 0xF2, 0x14, 0x18, 0x06,
    0xFF, 0xEF, 0x76, 0x84, 0x93, 0x2B, 0x94, 0xC3, 0x54, 0xE1, 0x73, 0x50,
    0xCC, 0x16, 0x58, 0x20, 0x9A, 0xB1, 0xEB, 0x8C, 0xA0, 0x54, 0x22, 0xE2,
    0xD7, 0x0E, 0x73, 0xEF, 0x82, 0x89, 0x18, 0x4C, 0xF8, 0xED, 0xCF, 0x4E,
    0x40, 0xDA, 0x39, 0x34, 0x7B, 0xA4, 0x04, 0x25, 0x55, 0x0C, 0xE6, 0x5F,
    0x17, 0x58, 0x20, 0xC7, 0xB3, 0x88, 0x6B, 0xBC, 0x90, 0x51, 0x07, 0x6F,
    0x5A, 0xD2, 0xD5, 0x30, 0x14, 0x2E, 0x7F, 0xBF, 0xAF, 0x31, 0x28, 0xCC,
    0x21, 0x39, 0x2F, 0xAF, 0x1D, 0x3E, 0xE0, 0xE5, 0xF8, 0x93, 0x3B, 0x18,
    0x18, 0x58, 0x20, 0x08, 0x36, 0x97, 0xC6, 0x64, 0x36, 0xB2, 0x5F, 0xCF,
    0x8A, 0xA0, 0xCC, 0x95, 0x56, 0x12, 0x6D, 0x94, 0x01, 0x20, 0x13, 0xA5,
    0x8C, 0x70, 0xF8, 0xE8, 0x85, 0xC0, 0x2D, 0x2F, 0x52, 0x38, 0xEC, 0x18,
    0x19, 0x58, 0x20, 0x03, 0x7B, 0xD4, 0x44, 0x7E, 0x09, 0xA5, 0xD7, 0xAA,
    0xDC, 0xB3, 0x59, 0x3D, 0x05, 0xE4, 0xC1, 0x7A, 0xA2, 0x30, 0xAF, 0x60,
    0xE7, 0xC8, 0xD3, 0x0C, 0x29, 0xAF, 0xC9, 0x7A, 0xD9, 0x81, 0x5D, 0x18,
    0x1A, 0x58, 0x20, 0x19, 0x70, 0xC3, 0xAC, 0x3C, 0x55, 0xD8, 0x27, 0x02,
    0xCE, 0x9F, 0x8E, 0xD7, 0x76, 0x08, 0x32, 0x38, 0x6E, 0x5F, 0xDD, 0xAF,
    0x4E, 0x35, 0x2D, 0x4C, 0xF9, 0x53, 0xA1, 0x5E, 0x40, 0xAC, 0xEC, 0x18,
    0x1B, 0x58, 0x20, 0xC4, 0xBB, 0xFA, 0xAF, 0x6B, 0xD4, 0x90, 0x96, 0x28,
    0x61, 0xF6, 0x33, 0x98, 0xDA, 0x8F, 0xAD, 0x19, 0xC2, 0x6E, 0x1D, 0xAC,
    0xD0, 0x7D, 0x52, 0x91, 0xE9, 0xA2, 0x2C, 0xDA, 0xF5, 0x31, 0x9E, 0x18,
    0x1C, 0x58, 0x20, 0x24, 0xAA, 0x53, 0xA9, 0xB4, 0x12, 0x0C, 0x19, 0x2D,
    0xF7, 0x90, 0xEE, 0x17, 0x0E, 0x38, 0x53, 0x56, 0x55, 0xFA, 0x56, 0x37,
    0xB6, 0x61, 0xC0, 0xEF, 0x26, 0xAA, 0x3B, 0x35, 0x7D, 0xB6, 0x04, 0x18,
    0x1D, 0x58, 0x20, 0x4E, 0x13, 0x96, 0xCC, 0xDC, 0x52, 0x7D, 0x29, 0x6D,
    0x65, 0x01, 0x84, 0x25, 0x68, 0x60, 0xEC, 0xE3, 0xF3, 0x79, 0xAD, 0x49,
    0x00, 0x89, 0x9F, 0x17, 0x15, 0x44, 0xAF, 0xF5, 0xB9, 0x50, 0xA3, 0x18,
    0x1E, 0x58, 0x20, 0x76, 0x48, 0xD8, 0x30, 0xA5, 0xF2, 0xD4, 0x93, 0x54,
    0xBA, 0x3E, 0x65, 0xF4, 0x49, 0x71, 0x31, 0xD6, 0x37, 0x48, 0xC7, 0x47,
    0x74, 0x8E, 0x79, 0x09, 0xBA, 0xEE, 0xEC, 0x82, 0x27, 0x9A, 0x76, 0x18,
    0x1F, 0x58, 0x20, 0x2E, 0xCD, 0xDA, 0x6B, 0xE9, 0x98, 0x5C, 0x3F, 0xCB,
    0xB2, 0xFB, 0x08, 0x52, 0xCC, 0x1F, 0x99, 0x40, 0x18, 0xA5, 0xAB, 0x13,
    0x10, 0x66, 0x1F, 0x7A, 0xD1, 0xFF, 0x44, 0xBB, 0x62, 0x2C, 0xF9, 0x18,
    0x20, 0x58, 0x20, 0xC6, 0x74, 0x42, 0x54, 0x8C, 0xCB, 0x44, 0x99, 0x68,
    0x23, 0x74, 0x85, 0x06, 0xD7, 0xFB, 0xE3, 0x88, 0x02, 0xF2, 0xAB, 0x95,
    0xB2, 0x93, 0x7F, 0xB9, 0xB4, 0xB5, 0xFB, 0x95, 0xCD, 0x36, 0x2E, 0x18,
    0x21, 0x58, 0x20, 0x77, 0x04, 0x87, 0xD5, 0x59, 0x05, 0x19, 0xE5, 0xE7,
    0x57, 0x85, 0x19, 0x9F, 0x0D, 0x17, 0x85, 0xDB, 0x09, 0x6E, 0x95, 0x94,
    0x34, 0xA0, 0xFF, 0xD1, 0x9D, 0x86, 0x64, 0x55, 0xA3, 0x87, 0xA8, 0x18,
    0x22, 0x58, 0x20, 0x12, 0xF6, 0xBC, 0x76, 0x67, 0x80, 0xE9, 0x05, 0x93,
    0x78, 0x49, 0x5C, 0xDE, 0x5E, 0x47, 0xF7, 0x8B, 0xE3, 0x51, 0xD5, 0x0D,
    0xD5, 0x3E, 0x51, 0x8E, 0xB3, 0xA6, 0x8F, 0xDF, 0xAF, 0xDC, 0xB3, 0x18,
    0x23, 0x58, 0x20, 0xD5, 0xB8, 0x48, 0xD4, 0xED, 0xB7, 0x68, 0x0C, 0x16,
    0x74, 0x62, 0x0B, 0x45, 0x47, 0x40, 0x02, 0xE2, 0x9A, 0x59, 0xE9, 0xB7,
    0x47, 0xC5, 0x98, 0x75, 0x71, 0x3F, 0x39, 0xD0, 0xDE, 0x43, 0x26, 0x18,
    0x24, 0x58, 0x20, 0xF1, 0x1E, 0x3E, 0xEC, 0x4B, 0xE5, 0x1A, 0xE1, 0x2E,
    0xAB, 0xFB, 0x52, 0xB4, 0xCA, 0xCA, 0x05, 0x9A, 0xDA, 0x76, 0x6F, 0xC5,
    0x59, 0x90, 0xF2, 0xC9, 0xC8, 0xAA, 0xE3, 0x6E, 0x3D, 0xC4, 0x15, 0x18,
    0x25, 0x58, 0x20, 0x7E, 0xD8, 0xD0, 0x9F, 0x03, 0x6A, 0x1D, 0x63, 0x05,
    0x18, 0x9E, 0xC7, 0x08, 0x65, 0x9C, 0x4B, 0xFD, 0x11, 0xE1, 0xF8, 0x13,
    0x48, 0xF5, 0x59, 0x46, 0x4B, 0xDE, 0xB8, 0xB7, 0x09, 0xBA, 0xC0, 0x18,
    0x26, 0x58, 0x20, 0x48, 0xFE, 0xAF, 0xFA, 0x4F, 0xE8, 0xA7, 0x1B, 0x41,
    0x7E, 0x91, 0x4A, 0xB7, 0xDE, 0xE1, 0x79, 0xB4, 0x97, 0x19, 0x9F, 0xE4,
    0x87, 0x9D, 0x89, 0x4D, 0xCB, 0x9D, 0x8C, 0xC6, 0x6B, 0xCD, 0x73, 0x18,
    0x27, 0x58, 0x20, 0xE5, 0xAE, 0xF9, 0x86, 0xF9, 0xD6, 0x24, 0x70, 0xBC,
    0x15, 0x4E, 0x10, 0x3E, 0xEC, 0x19, 0x10, 0x53, 0xAD, 0xAB, 0x46, 0x6A,
    0x10, 0x1C, 0x4A, 0x4E, 0xA3, 0xEE, 0x1A, 0x1E, 0x02, 0x5C, 0x2C, 0x18,
    0x28, 0x58, 0x20, 0xBA, 0xAE, 0x3D, 0xD3, 0xE7, 0xEA, 0xAA, 0x5F, 0xB8,
    0x4F, 0x24, 0xE5, 0x75, 0x22, 0x39, 0x02, 0xB1, 0x38, 0xF8, 0x54, 0x57,
    0x52, 0x13, 0xCB, 0xB7, 0x0D, 0x74, 0x1A, 0xB4, 0x66, 0xF0, 0x15, 0x18,
    0x29, 0x58, 0x20, 0x4C, 0xB1, 0x32, 0x39, 0x6A, 0xBC, 0x65, 0x8F, 0xED,
    0xDC, 0x1A, 0x7C, 0x2A, 0x6A, 0x4D, 0x1C, 0xD4, 0x58, 0xD2, 0x38, 0x05,
    0x48, 0x8E, 0x28, 0x7A, 0x2B, 0xDC, 0x02, 0x0C, 0x9B, 0x4E, 0xFE, 0x18,
    0x2A, 0x58, 0x20, 0xEC, 0x64, 0xD6, 0x5D, 0x48, 0x30, 0xB6, 0x01, 0x3F,
    0x70, 0xB0, 0xF2, 0x17, 0x28, 0x78, 0x8C, 0x2F, 0xD3, 0x72, 0x12, 0x6C,
    0xB5, 0x1A, 0xB1, 0xE5, 0xF7, 0xD2, 0x6B, 0x83, 0x03, 0x60, 0x22, 0x73,
    0x6F, 0x72, 0x67, 0x2E, 0x61, 0x61, 0x6D, 0x76, 0x61, 0x2E, 0x31, 0x38,
    0x30, 0x31, 0x33, 0x2E, 0x35, 0x2E, 0x31, 0xA7, 0x00, 0x58, 0x20, 0xBD,
    0x12, 0x05, 0xF8, 0x26, 0x49, 0x6C, 0xED, 0xD8, 0x42, 0x71, 0x85, 0x46,
    0x28, 0x98, 0x4D, 0x76, 0xC6, 0x2A, 0xB6, 0xB7, 0xD4, 0xF6, 0x8E, 0x04,
    0x65, 0x8D, 0x4E, 0x63, 0xDA, 0xA4, 0x10, 0x01, 0x58, 0x20, 0x28, 0xA2,
    0xA6, 0xF3, 0xFB, 0x47, 0xEE, 0x49, 0x75, 0x8A, 0x06, 0xBE, 0x56, 0xB7,
    0x5D, 0xA5, 0x98, 0x0A, 0x2E, 0xF7, 0xD4, 0xD6, 0xC6, 0xB0, 0x04, 0x02,
    0xC1, 0x02, 0x3C, 0x97, 0xBE, 0xF6, 0x02, 0x58, 0x20, 0xDA, 0xF1, 0x0E,
    0x80, 0xD8, 0x7E, 0xDD, 0xA4, 0x05, 0x1B, 0xF1, 0x21, 0x89, 0x5C, 0xAD,
    0x3F, 0xC5, 0x95, 0xDB, 0x8D, 0x5A, 0xEB, 0x35, 0x26, 0xDE, 0x70, 0x4B,
    0x6F, 0x0E, 0x77, 0xAC, 0xFA, 0x03, 0x58, 0x20, 0xA6, 0xF8, 0x0A, 0x0C,
    0xBF, 0x80, 0xF4, 0x2C, 0xC3, 0x3E, 0x08, 0xF9, 0x8E, 0x0D, 0x85, 0xCF,
    0xC5, 0xA4, 0xB9, 0x7D, 0x13, 0xC5, 0xD4, 0xBA, 0xD8, 0x99, 0x2B, 0xFE,
    0x5A, 0xBD, 0x9A, 0x92, 0x04, 0x58, 0x20, 0x06, 0x26, 0x32, 0x51, 0x0E,
    0xEF, 0xBB, 0x33, 0x8C, 0x12, 0x22, 0x8D, 0x8C, 0xA2, 0x99, 0xD4, 0xC0,
    0x7C, 0x34, 0xF1, 0x2C, 0xCC, 0xF8, 0x6C, 0x51, 0x94, 0x72, 0x52, 0x8D,
    0x8F, 0xBC, 0x9A, 0x05, 0x58, 0x20, 0xCE, 0x4F, 0x35, 0x15, 0xE7, 0xC2,
    0x56, 0x09, 0x5A, 0xC6, 0xB6, 0xAA, 0x4A, 0x4A, 0xF0, 0xAC, 0x8B, 0x96,
    0x40, 0x79, 0xBD, 0x62, 0x7B, 0xC8, 0x97, 0xF5, 0x44, 0x08, 0x7F, 0x2D,
    0x2C, 0x7B, 0x06, 0x58, 0x20, 0x92, 0x1A, 0xEC, 0x9F, 0xA8, 0xC5, 0x1C,
    0x6F, 0x90, 0xDE, 0x86, 0x0F, 0x6E, 0x5F, 0x4D, 0x81, 0xC7, 0x56, 0xF6,
    0x2A, 0x8F, 0xE6, 0xE1, 0x9D, 0x91, 0x22, 0xE9, 0x42, 0xDD, 0xB9, 0xBF,
    0xA3, 0x6D, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B, 0x65, 0x79, 0x49,
    0x6E, 0x66, 0x6F, 0xA1, 0x69, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x4B,
    0x65, 0x79, 0xA4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0x61, 0xDC,
    0x8B, 0x2C, 0x6E, 0x98, 0xE1, 0xA2, 0x82, 0xB1, 0x6F, 0x95, 0xF3, 0x73,
    0xC1, 0xB0, 0xB9, 0x9E, 0xE4, 0x7F, 0xA5, 0x71, 0x91, 0x76, 0x3F, 0x08,
    0xB2, 0xFC, 0x1E, 0xBE, 0x9A, 0xF5, 0x22, 0x58, 0x20, 0x10, 0xCF, 0x01,
    0x63, 0x7F, 0x63, 0xCB, 0x7C, 0x53, 0xF8, 0x92, 0x5F, 0xD2, 0xA3, 0x7D,
    0xED, 0xEC, 0x6D, 0x04, 0xEA, 0xAB, 0xE4, 0xDC, 0xCA, 0x94, 0x43, 0x79,
    0x62, 0x81, 0x3A, 0xAF, 0x1C, 0x6C, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x69,
    0x74, 0x79, 0x49, 0x6E, 0x66, 0x6F, 0xA3, 0x66, 0x73, 0x69, 0x67, 0x6E,
    0x65, 0x64, 0xC0, 0x74, 0x32, 0x30, 0x32, 0x34, 0x2D, 0x30, 0x32, 0x2D,
    0x31, 0x34, 0x54, 0x30, 0x38, 0x3A, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x5A,
    0x69, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x46, 0x72, 0x6F, 0x6D, 0xC0, 0x74,
    0x32, 0x30, 0x32, 0x34, 0x2D, 0x30, 0x32, 0x2D, 0x31, 0x34, 0x54, 0x30,
    0x38, 0x3A, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x5A, 0x6A, 0x76, 0x61, 0x6C,
    0x69, 0x64, 0x55, 0x6E, 0x74, 0x69, 0x6C, 0xC0, 0x74, 0x32, 0x30, 0x32,
    0x35, 0x2D, 0x30, 0x32, 0x2D, 0x31, 0x34, 0x54, 0x30, 0x38, 0x3A, 0x30,
    0x30, 0x3A, 0x30, 0x30, 0x5A, 0x67, 0x64, 0x6F, 0x63, 0x54, 0x79, 0x70,
    0x65, 0x75, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x73, 0x6F, 0x2E, 0x31, 0x38,
    0x30, 0x31, 0x33, 0x2E, 0x35, 0x2E, 0x31, 0x2E, 0x6D, 0x44, 0x4C,
};

template <class Field>
void test_parser(const Field& F) {
  using CborWitness = CborWitness<Field>;
  using CborTesting = CborTesting<Field>;

  using EvalBackend = EvaluationBackend<Field>;
  using Logic = Logic<Field, EvalBackend>;
  using CborL = Cbor<Logic>;

  const EvalBackend ebk(F);
  const Logic L(&ebk, F);
  const CborL CBOR(L);
  const CborTesting CT(F);
  const CborWitness CW(F);

  size_t input_len = mso_nbytes;
  size_t n = input_len;

  std::vector<typename CborWitness::v8> inS(n);
  std::vector<typename CborWitness::position_witness> pwS(n);
  CW.compute_witnesses(n, input_len, mso_example, inS.data(), pwS.data());

  std::vector<typename CborL::v8> in(n);
  std::vector<typename CborL::position_witness> pw(n);
  CT.convert_witnesses(n, in.data(), pw.data(), inS.data(), pwS.data());

  std::vector<typename CborL::decode> ds(n);
  std::vector<typename CborL::parse_output> ps(n);
  CBOR.decode_and_assert_decode_and_parse(n, ds.data(), ps.data(), in.data(),
                                          pw.data());

  // assert a map entry with a 1 byte index
  CBOR.assert_map_entry(n,
                        CT.index(1886),  // devKey.v,
                        2,
                        CT.index(1926),  // devKeyPky.k,
                        CT.index(1927),  // devKeyPky.v,
                        CT.index(3),     // devKeyPky.ndx,
                        ds.data(), ps.data());

  // assert a map entry with a 2-byte index
  CBOR.assert_map_entry(n, CT.index(69),  // org.v,
                        2,
                        CT.index(246),  // k pos for entry 5
                        CT.index(247),  // v pos for entry 5
                        CT.index(5),    // index = 5
                        ds.data(), ps.data());
}

TEST(CborParser, MSOPrimeField) { test_parser(Fp<1>("18446744073709551557")); }

TEST(CborParser, MSOBinaryField) { test_parser(GF2_128<>()); }
}  // namespace
}  // namespace proofs
